const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost:27017/linj', {useNewUrlParser: true});
let db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
    console.log('connect')
});
var userSchema = new mongoose.Schema({
    username: String,
    email: String,
    tel: Number,
});
var model = mongoose.model('user', userSchema);
var newUser = new model({
    username: 'linj',
    email: 'a@qq.com',
    tel: 15920385215
});
newUser.save(function(err, data){
    if(err){ return console.log(err) }
    console.log('success',data);
});
exports.db = db;